#include <iostream>
#include <ostream>
#include <vector>
#include <algorithm>

class Student
{
private:
    int age;
    std::string name;
public :
    int getAge() const
    {
        return age;
    }

    std::string getName() const
    {
        return name;
    }

    Student()
    {}

    Student(std::string name, int age) : name(name), age(age)
    {}

    friend std::ostream& operator<<(std::ostream& os, const Student& stu);
};

std::ostream& operator<<(std::ostream& os, const Student& stu)
{
    os << "name = " << stu.getName() << ", age = " << stu.getAge();
    return os;
}

class Younger
{
public:
    bool operator()(const Student& stu)
    {
        return stu.getAge() < 18;
    }
};

class Sort{
public:
    bool operator() (const Student& stu1, const Student& stu2) {
        return stu1.getAge() < stu2.getAge();
    }
};


int main()
{

    std::vector<Student> vector{};

    srand(time(0));

    for (int i = 0; i < 10; i++)
    {
        char cap = rand() % 26 + 65;
        char letter1 = rand() % 26 + 97;
        char letter2 = rand() % 26 + 97;
        char letter3 = rand() % 26 + 97;
        char letter4 = rand() % 26 + 97;
        char letter5 = rand() % 26 + 97;
        char* array = new char[]{cap, letter1, letter2, letter3, letter4, letter5};
        vector.emplace_back(std::string(array), rand() % 30 + 5);
    }

#if 0
    std::vector<Student>::const_iterator it = std::find_if(vector.begin(), vector.end(), Younger());

    if (it != vector.end())
    {
        std::cout << *it << std::endl;
    }
#else
    std::vector<Student> youngerVector{};
    std::copy_if(vector.begin(), vector.end(), std::back_inserter(youngerVector), Younger());
    if (!youngerVector.empty()) {
        for (const Student& stu: youngerVector) {
            std::cout << stu << std::endl;
        }
    }
#endif
    else
    {
        std::cout << "没有发现未成年学生" << std::endl;
    }

    std::cout << std::string(20, '#') << std::endl;
    std::sort(vector.begin(), vector.end(), Sort());

    for (const Student& stu: vector) {
        std::cout << stu << std::endl;
    }

    return EXIT_SUCCESS;
}